package com.kennedy.springbootjpa.beans.common;

import java.util.Map;

public class ResultMsg<T> {
    private String error;

    private Integer errorCode; // 0正确 -1错误 其他错误码带定

    private T returnInfo = null;

    public String getError() {
        return error;
    }

    public void setError(String error) {
        this.error = error;
    }

    public Integer getErrorCode() {
        return errorCode;
    }

    public void setErrorCode(Integer errorCode) {
        this.errorCode = errorCode;
    }

    public T getReturnInfo() {
        return returnInfo;
    }

    public void setReturnInfo(T returnInfo) {
        this.returnInfo = returnInfo;
    }

    public static ResultMsg<Map<String, Object>> success() {
        ResultMsg<Map<String, Object>> success = new ResultMsg<>();
        success.setErrorCode(0);
        return success;
    }

    public static <T> ResultMsg<T> success(T returnInfo) {
        ResultMsg<T> success = new ResultMsg<>();
        success.setReturnInfo(returnInfo);
        success.setErrorCode(0);
        return success;
    }

    public static <T> ResultMsg<T> error(String errorMsg) {
        ResultMsg<T> error = new ResultMsg<>();
        error.error = errorMsg;
        error.errorCode = -1;
        return error;
    }

    public static <T> ResultMsg<T> error() {
        ResultMsg<T> error = new ResultMsg<>();
        error.error = "服务器异常";
        error.errorCode = -1;
        return error;
    }


    public static <T> ResultMsg<T> error(String errorMsg, Integer errorCode) {
        ResultMsg<T> error = new ResultMsg<>();
        error.error = errorMsg;
        error.errorCode = errorCode;
        return error;
    }
}
